const { app, BrowserWindow } = require("electron");
const path = require("path");
require('./controller/getSource')
//保存窗口状态
const WinState = require("electron-win-state").default;

const createWindow = () => {
    const winState = new WinState({
        defaultWidth: 800,
        defaultHeight: 600,
    });
    const win = new BrowserWindow({
        //自定义窗口状态 大小位置
        ...winState.winOptions,
        webPreferences: {
            preload: path.resolve(__dirname, "./preload/index.js"),
        },
        show:false,
    });
    winState.manage(win);
    win.loadURL("http://localhost:80");
    win.webContents.openDevTools();
    //优雅的打开窗口
    win.on('ready-to-show',()=>{
        win.show()
    })
};
//检测窗口的关闭   最后一个窗口
app.on("window-all-closed", () => {
    //对于macOS系统   关闭窗口时，不会直接退出应用
    // darwin mac系统名字
    if (process.platform !== "darwin") app.quit();
});
app.whenReady().then(() => {
    createWindow();
    app.on("activate", () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow();
    });
});
